/*
 * Copyright (c) 2013-2015 Charkey. All rights reserved.
 *
 * This software is the confidential and proprietary information of Charkey.
 * You shall not disclose such Confidential Information and shall use it only
 * in accordance with the terms of the agreements you entered into with Charkey.
 *
 * Charkey MAKES NO REPRESENTATIONS OR WARRANTIES ABOUT THE SUITABILITY OF THE SOFTWARE,
 * EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED
 * WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, OR NON-INFRINGEMENT.
 *
 * Charkey SHALL NOT BE LIABLE FOR ANY DAMAGES SUFFERED BY LICENSEE AS A RESULT OF USING,
 * MODIFYING OR DISTRIBUTING THIS SOFTWARE OR ITS DERIVATIVES.
 */

package cn.simastudio.talos.inter.controller.web;

import cn.simastudio.talos.common.authc.hmac.HmacAuthRequest;
import cn.simastudio.talos.common.utils.hmac.HmacAuthUtils;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpServletRequest;

/**
 * Usage:
 *
 * @author Charkey
 * @date 2015/5/19 9:37
 */
@Controller
@RequestMapping("/header")
public class TestHeaderController {

    @ResponseBody
    @RequestMapping(value = "/get", method = RequestMethod.GET)
    public String header(HttpServletRequest request, String name) {
        HmacAuthRequest authRequest = new HmacAuthRequest(request);
        System.out.println("id/uuid: " + authRequest.getId());
        System.out.println("nonce: " + authRequest.getNonce());
        System.out.println("mac: " + authRequest.getMac());
        System.out.println("validate result: " + HmacAuthUtils.validate(authRequest));
        System.out.println("Url Parameter:name=" + name);
        return "";
    }

}
